{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ec101e34",
   "metadata": {},
   "source": [
    "  ##  上周回顾\n",
    " > * list方法/函数的所有的使用场景及案例\n",
    " >> 1.append()\n",
    " >> 2.pop(index)/remove(values)\n",
    " >> 3.count() 查看数量\n",
    " >> 4.index() 查看索引值\n",
    " >> 5.extend()\n",
    " >> 6.sort()\n",
    " >> ...\n",
    " > * list高级用法 如：\n",
    " >> 1.copy()复制不等于赋值，复制可等于切片[:]\n",
    " >> 2.enu\n",
    " > * 课本练习（课堂上带大家做了）Don't panic ==> on tap,其中知识点；\n",
    " >> 1.list的一些方法实现\n",
    " >> 2.list的切片实现\n",
    " >> 3.str => list的方法 list(str)\n",
    " >> 4.list => str的方法 ''.join(list)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f83c88c",
   "metadata": {},
   "source": [
    "  ## 本周练习\n",
    "  ## 简单练习"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "86b6dadc",
   "metadata": {},
   "source": [
    "·1.vowels2.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "0421fefe",
   "metadata": {},
   "outputs": [],
   "source": [
    "vowels = ['a','e','i','o','u'] # 这是元音 (list)\n",
    "word = \"Milliways\" # 这是文本 (str)\n",
    " # 需求: word 中出现的 vowels 打印出来\n",
    " # for word in vowels (word)\n",
    " # for i in vowels (i,先操作word)\n",
    " # for letter in word(课本 letter是否可以修改？)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "23ceeccc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\n",
      "e\n",
      "i\n",
      "o\n",
      "u\n"
     ]
    }
   ],
   "source": [
    "for word in vowels: # 循环遍历的第一个位置的元素请注意！\n",
    "    print(word)     #名字(for 后面的word)不要和已经定义过的变量重复"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "32fc2a9c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\n",
      "e\n",
      "i\n",
      "o\n",
      "u\n"
     ]
    }
   ],
   "source": [
    "for i in vowels: # for循环的第二个元素(vowels内容)，决定了我们循环的内容\n",
    "    print(i)     # 循环的列表，每个元素单独在一行打印"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "8b3cafdb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "u\n"
     ]
    }
   ],
   "source": [
    "for letter in word: # letter可以随意命名，不会影响结果\n",
    " #     print(letter)   # 一般情况下，item（内容） ==>简写为i\n",
    "   if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "f13a86a0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['u']"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " # append()经常用于新建列表\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "found"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1fd69d94",
   "metadata": {},
   "source": [
    " ## 数据结构课后练习\n",
    " ```\n",
    " 购物车程序项目：\n",
    "\n",
    "要求：1、运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    "\n",
    "　　   2、让用户输入商品编号进行商品的购买。\n",
    "\n",
    "　　   3、用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。\n",
    "\n",
    "　　   4、用户可以随时退出购买，推出时打印用户已购买的商品和支付宝余额。\n",
    "     \n",
    " ```    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8d4dded2",
   "metadata": {},
   "outputs": [],
   "source": [
    " ### 商品列表\n",
    " goods_list = [\n",
    "     [\"cloth\",399],\n",
    "     [\"shoes\",3999],\n",
    "     [\"watch\",13999],\n",
    "     [\"puzzle\",199] \n",
    " ]\n",
    " ### 用户购买列表\n",
    "user_shopping_list = []\n",
    " ### 用户输入(余额):   # ------知识点:打印与用户输入 ------\n",
    " Alipay = int(input(\"请输入您的支付宝余额:\"))\n",
    " info = '''------ goods detail ------\n",
    " 编号0，商品名称：%s，商品的价格：%s 元\n",
    " 编号1，商品名称：%s，商品的价格：%s 元\n",
    " 编号2，商品名称：%s，商品的价格：%s 元\n",
    " 编号3，商品名称：%s，商品的价格：%s 元\n",
    " '''%(goods_list[0][0],goods_list[0][1],\n",
    "     goods_list[1][0],goods_list[1][1],\n",
    "     goods_list[2][0],goods_list[2][1],\n",
    "     goods_list[3][0],goods_list[3][1],)\n",
    " print(info)   \n",
    " ### 是不是应该循环了呢？\n",
    "While True:\n",
    "    print(\"------goods_list------\")\n",
    "    # for循环的优势，减少重复代码的书写 \n",
    "for i in range(4):\n",
    "   \n",
    "    print(\"编号%s,商品名称:%s,商品价格:%s元,\"\n",
    "         %(i,goods_list[i][0],goods_list[i][1]))\n",
    "    \n",
    "    ### 用户输入商品编号\n",
    "    choice = int(input(\"请输入购买商品编号:\"))\n",
    "    ### 1.输入编号存在，判断余额是否足够\n",
    "    if choice < len(goods_list):        \n",
    "                ### 1.余额够，用户余额-商品价格\n",
    "        if goods_list[choice][1] < Alipay:\n",
    "            Alipay = Alipay - goods_list[choice][1]\n",
    "            print(\"您的商品购买成功，已添加到购物车，您的余额还有%s\"%(Alipay))\n",
    "            else:\n",
    "                print(\"您的余额不足，请用花呗吧!\")\n",
    "     \n",
    "        ### 2.余额不足，“您的余额不足”\n",
    "        else:\n",
    "            print(\"您输入的商品编号可能超过我们的商品范围或不存在这个商品\")\n",
    "        ### 2.\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ace0dc40",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "54637021",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "165px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
